package com.common.jump;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

import com.orangelife.mobile.app.application.CurryApplication;
import com.orangelife.mobile.login.activity.Login2Activity;
import com.orangelife.mobile.login.activity.SelectCityActivity;
import com.orangelife.mobile.main.activity.MainTablActivity;
import com.thirdsdk.baidu.BaiduLocationActivity;
import com.curry.android.util.IntentHelper;
import com.orangelife.mobile.shoppingcart.activity.ShoppingCartActivity;

/**
 * 通用的Activity跳转（多个模块公用）
 * <p/>
 * Created by wgf on 2016/6/22.
 *
 * @author wgf
 * @since v3.8
 */
public class CommonJumper {

    /** JPush用，跳转到主界面，开启新栈 */
    public static void jumpToMainWithNewTask(Context context, String webViewUrl) {
        jumpToMain(context, Intent.FLAG_ACTIVITY_NEW_TASK, webViewUrl);
    }

    /** App内跳转到主界面 */
    public static void jumpToMain(Context context) {
        jumpToMain(context, -1, null);
    }

    public static void jumpToMain(Context context, int flag, String webViewUrl) {
        IntentHelper.getInstances().intentWithExtra(context, MainTablActivity.class, "WebViewUrl", webViewUrl, flag);
    }


    //退出登录,CurryApplication专用，实现了ErrorHandler对登录过期的回调接口
    public static void jumpToLoginWhenExit(Context context) {
        jumpToLogin(context, null, true);
    }

    public static void jumpToLoginWhenExitWithClear(Context context) {
        CurryApplication.getInstance().exit();
        CurryApplication.getInstance().clearToken();
        jumpToLogin(context, null, true);
    }

    //引导页
    public static void jumpToLogin(Context context) {
        jumpToLogin(context, null, false);
    }

    //JPUSH专用
    public static void jumpToLoginWithJPush(Context context, Uri uri) {
        jumpToLogin(context, uri, true);
    }

    public static void jumpToLogin(Context context, Uri uri, boolean isNeedNewTask) {
        Intent intent = new Intent(context, Login2Activity.class);
        if (isNeedNewTask) {
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        if (uri != null) {
            intent.putExtra("jPush", true);
            intent.putExtra("uri", uri);
        }
        context.startActivity(intent);
        IntentHelper.getInstances().jumpActivityAnimation(context,false);
    }

    public static void jumpToBaiduLocation(Context context, float longitude, float latitude) {
        Intent intent = new Intent();
        intent.setClass(context,
                BaiduLocationActivity.class);
        Bundle bundle = new Bundle();
        bundle.putFloat("longitude", longitude);
        bundle.putFloat("latitude", latitude);
        intent.putExtras(bundle);
        context.startActivity(intent);
    }

    public static void jumpToShoppingCart(Context context) {
        //跳转购物车页面
        IntentHelper.getInstances().getIntent(context, ShoppingCartActivity.class);
    }


}
